# 正向查询和反向查询

# 具有外键关系： 直接查
# 没有外键关系：
# （1） 查询书籍主键为 4 的出版社的名字
# book_obj = Book.objects.get(id=4)
# publish_obj = Publish.objects.get(id=book_obj.publish_id)
# publish_obj.name

# (2) 查询作者主键为 1 的书籍的名字
# author_obj = Author.objects.get(id=1)
# book_obj_list = Book.objects.fileter(author_id=author_obj.id)
# book_name_list = [book.name for book in book_obj_list]

# (3) 查询书籍主键为 1 的作者的性别
# book_obj = Book.objects.get(id=1)
# author_obj = Author.objects.get(id=book_obj.author_id)
# sex = author_obj.sex


# 基于双下划线的多表查询
# 查询书籍 dream_0 的手机号和作者姓名
# book_obj = Book.objects.get(name='dream_0')
# author_obj = Author.objects.get(id=book_obj.author_id)
# print(author_obj.phone, author_obj.name)
# 一对一关系，直接查两外一张表中的数据
# book_obj = Book.objects.filter(name='dream_0').values("name", "detail__phone")

# AuthorDetail.objects.filter(author__name="dream_0").values()
